package com.jiangnan.artstudio.fragment;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiangnan.artstudio.R;

public class MineCyglMainFragment extends BaseFragment {

    private ImageView back;
    private TextView zr,cy,xx;
    private FragmentManager fManager;
    private DongTai dongTai;
    private JianJie jianJie;
    private XiangMu xiangMu;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mine_cygl_main,container,false);

        findViewId(view);
        initTitle(view);
        fManager = getFragmentManager();

        onClick();
        zr.performClick();
        return view;
    }
    public void setNormal(){
        zr.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        cy.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        xx.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
    }

    public void hideAllFragment(FragmentTransaction fragmentTransaction){
        if(dongTai != null)fragmentTransaction.hide(dongTai);
        if(xiangMu != null)fragmentTransaction.hide(xiangMu);
        if(jianJie != null)fragmentTransaction.hide(jianJie);
    }

    public void findViewId(View v) {
        back = v.findViewById(R.id.cygl_back);
        zr = v.findViewById(R.id.zhir);
        cy = v.findViewById(R.id.chengyuan);
        xx = v.findViewById(R.id.xiaoxi);
    }

    public void onClick() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fm = getActivity().getSupportFragmentManager();
                fm.beginTransaction()
                        //替换为TwoFragment
                        .replace(R.id.main_content,new MineFragment())
                        .commit();
            }
        });
        zr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentTransaction fTransaction = fManager.beginTransaction();
                hideAllFragment(fTransaction);
                setNormal();
                zr.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                fTransaction.add(R.id.mine_cygl_content,new CyglZhiR()).commit();
            }
        });
        cy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentTransaction fTransaction = fManager.beginTransaction();
                hideAllFragment(fTransaction);
                setNormal();
                cy.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                fTransaction.add(R.id.mine_cygl_content,new CyglChengYuan()).commit();
            }
        });
        xx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentTransaction fTransaction = fManager.beginTransaction();
                hideAllFragment(fTransaction);
                setNormal();
                xx.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                fTransaction.add(R.id.mine_cygl_content,new CyglXiaoXi()).commit();
            }
        });

    }
}